{ Summer Informatics School.
  Problemset: http://agul-problems1.googlecode.com/svn/trunk/2010-2011/sis/problemset11.pdf
  Problem J
  Points: 100
}
uses SysUtils,math;
var i,n,c,r,ls,j:longint; prost:array[0..10000010] of byte; a:array[0..1000010] of longint; s,t:string;
procedure erat(max:longint);
var i,j:longint;
begin
fillchar(prost,sizeof(prost),0);
for i:=2 to max do begin
  if prost[i]=0 then begin
    prost[i]:=1;
    j:=i*2;
    while j<=max do begin
      prost[j]:=2;
      inc(j,i);
    end;
  end;
end;
end; 
begin
read(n);
erat(9999999);
c:=0;
for i:=2 to n do 
	if prost[i]=1 then begin
		inc(c);
		a[c]:=i;
	end;
r:=0;
for i:=1 to c do begin
	s:=inttostr(a[i]);
	ls:=length(s);
	t:='';
	for j:=ls downto 1 do t:=t+s[j];
	if prost[strtoint(t)]=1 then inc(r);	
end;
write(r); 
end.
